﻿(function () {
    'use strict';
    var app = angular.module('app');

    app.controller("providerChooseCtrl", ["$scope", "config", "departmentService", "providerService", function ($scope, config, departmentService, providerService) {
        $scope.institutionName = config.user.currentInstitutionName;

        departmentService.getByInstitution(config.user.currentInstitutionId)
            .then(function(result) {
                $scope.departments = result;
                $scope.dep = $scope.departments[0];
            }).then(function(r) {
                providerService.getByDepartment($scope.dep.data).then(function(res) {
                    $scope.providers = res;
                    $scope.pro = $scope.providers[0];
                });
                
            });

        $scope.changeDepartment = function(dep) {
            providerService.getByDepartment(dep.data).then(function(res) {
                $scope.providers = res;
                $scope.pro = $scope.providers[0];
            });
        };        
        

    }]);

}());
